home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher+1.2b4 / gopherd / ext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-11  |  6.2 KB  |  288 lines

  1. /********************************************************************
  2.  * lindner
  3.  * 3.1.1.1
  4.  * 1993/02/11 18:02:51
  5.  * /home/mudhoney/GopherSrc/CVS/gopher+/gopherd/ext.c,v
  6.  * Exp
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: ext.c
  14.  * These fns define mapping of file extensions to gopher objects.
  15.  *********************************************************************
  16.  * Revision History:
  17.  * ext.c,v
  18.  * Revision 3.1.1.1  1993/02/11  18:02:51  lindner
  19.  * Gopher+1.2beta release
  20.  *
  21.  * Revision 1.3  1993/02/09  22:13:19  lindner
  22.  * many additions for multilingual gopher
  23.  *
  24.  * Revision 1.2  1993/01/30  23:56:55  lindner
  25.  * Lots of new code for gopher+ stuff..  Change everything to start with EX
  26.  *
  27.  * Revision 1.1  1992/12/10  23:13:27  lindner
  28.  * gopher 1.1 release
  29.  *
  30.  *
  31.  *********************************************************************/
  32.  
  33. #include "ext.h"
  34. #include "Malloc.h"
  35. #include <ctype.h>
  36. #include "util.h"
  37.  
  38. extern boolean DEBUG;
  39.  
  40. /*
  41.  * Some functions to initialize and destroy sites and extensions..
  42.  * (Needed for use with DynArrays...)
  43.  */
  44.  
  45. Extobj *
  46. EXnew()
  47. {
  48.      Extobj *temp;
  49.  
  50.      temp = (Extobj *) malloc(sizeof(Extobj));
  51.      
  52.      if (temp == NULL)
  53.       return(NULL);
  54.  
  55.      temp->Objtype   = '\0';
  56.      temp->View      = STRnew();
  57.      temp->ViewLang  = STRnew();
  58.      temp->Prefix    = STRnew();
  59.      temp->ext       = STRnew();
  60.      temp->exttype   = EXT_ERROR;
  61.      temp->Blockname = STRnew();
  62.  
  63.      STRinit(temp->View);
  64.      STRinit(temp->ViewLang);
  65.      STRinit(temp->Prefix);
  66.      STRinit(temp->ext);
  67.      STRinit(temp->Blockname);
  68.      
  69.      return(temp);
  70. }
  71.  
  72.  
  73. /** Destroy an extension structure **/
  74.  
  75. void 
  76. EXdestroy(ext)
  77.   Extobj *ext;
  78. {
  79.      STRdestroy(ext->View);
  80.      STRdestroy(ext->ViewLang);
  81.      STRdestroy(ext->Prefix);
  82.      STRdestroy(ext->ext);
  83.      STRdestroy(ext->Blockname);
  84.      
  85.      free(ext);
  86. }
  87.  
  88.  
  89. /** Copy an extension structure **/
  90.  
  91. void
  92. EXcpy(ext1, ext2)
  93.   Extobj *ext1, *ext2;
  94. {
  95.      ext1->Objtype  = ext2->Objtype;
  96.      STRcpy(ext1->View, ext2->View);
  97.      STRcpy(ext1->ViewLang, ext2->ViewLang);
  98.      STRcpy(ext1->Prefix, ext2->Prefix);
  99.      STRcpy(ext1->ext, ext2->ext);
  100.      STRcpy(ext1->Blockname, ext2->Blockname);
  101.      EXsetExttype(ext1, EXgetExttype(ext2));
  102. }
  103.  
  104. /*
  105.  * Get the parameters associated with a particular extension
  106.  *
  107.  * Fills in ext with the values..
  108.  */
  109.  
  110. boolean
  111. EXAsearch(extarr, ext, fileext, exttype)
  112.   ExtArray *extarr;
  113.   Extobj *ext;
  114.   char *fileext;
  115.   int exttype;
  116. {
  117.      int i, extlen;
  118.      Extobj *temp;
  119.  
  120.      extlen = strlen(fileext);
  121.  
  122.      /*** Linear search.  Ick. ***/
  123.      
  124.      for (i=0; i< EXAgetNumEntries(extarr); i++) {
  125.  
  126.       temp = EXAgetEntry(extarr,i);
  127.       
  128.       if (strcasecmp(fileext+extlen-strlen(EXgetExt(temp)), EXgetExt(temp)) == 0) {
  129.            
  130.            if (exttype == EXgetExttype(temp)) {
  131.             EXcpy(ext,temp);
  132.             return(TRUE);
  133.            }
  134.       }
  135.      }
  136.      return(FALSE);
  137. }
  138.  
  139.  
  140. /*
  141.  * Search for a specific view extension...
  142.  */
  143.  
  144. boolean
  145. EXAviewSearch(extarr, ext, view)
  146.   ExtArray *extarr;
  147.   Extobj   *ext;
  148.   char     *view;
  149. {
  150.      int    i;
  151.      Extobj *temp;
  152.      char   viewnlang[256];
  153.  
  154.      /*** Linear search.  Ick. ***/
  155.      
  156.      for (i=0; i< EXAgetNumEntries(extarr); i++) {
  157.  
  158.       temp = EXAgetEntry(extarr,i);
  159.  
  160.       if (EXgetExttype(temp) == EXT_VIEW) {
  161.  
  162.            strcpy(viewnlang, EXgetView(temp));
  163.            if (EXgetVLang(temp) != NULL) {
  164.             strcat(viewnlang, " ");
  165.             strcat(viewnlang, EXgetVLang(temp));
  166.            }
  167.            
  168.            if (strcasecmp(view, viewnlang)==0) {
  169.             EXcpy(ext,temp);
  170.             return(TRUE);
  171.            }
  172.       }
  173.      }
  174.      return(FALSE);
  175.      ;
  176. }
  177.  
  178.  
  179. /*
  180.  * Process gopherd.conf lines "viewext", "ignore", "blockext" and others.
  181.  */
  182.  
  183.  
  184. boolean 
  185. EXAprocessLine(extarr, exttype, inputline, deflang)
  186.   ExtArray *extarr;
  187.   int       exttype;
  188.   char     *inputline;
  189.   char     *deflang;
  190. {
  191.      int    i;
  192.      char   ext[64];
  193.      char   secondparm[64];
  194.      char   prefix[64];
  195.      char   Gplustype[64];
  196.      char   Gpluslang[16];
  197.      Extobj *temp;
  198.  
  199.      temp = EXnew();
  200.  
  201.      /*** Set the type of extension we've been given ***/
  202.      EXsetExttype(temp, exttype);
  203.  
  204.      if (deflang != NULL)
  205.       EXsetVLang(temp, deflang);
  206.  
  207.  
  208.      inputline = skip_whitespace(inputline);
  209.      if (*inputline == '\0') return(FALSE);
  210.  
  211.      /*** The first parameter, the extension ***/
  212.      i=0;
  213.      while (!isspace(*inputline) && (*inputline != '\0'))
  214.       ext[i++] = *inputline++;
  215.  
  216.      ext[i] = '\0';
  217.      EXsetExt(temp,ext);
  218.  
  219.      
  220.      inputline = skip_whitespace(inputline);
  221.  
  222.      if (exttype == EXT_IGNORE) {
  223.       EXAadd(extarr, temp);
  224.       EXdestroy(temp);
  225.       return(TRUE);
  226.      }
  227.  
  228.      if (*inputline == '\0') return(FALSE);
  229.  
  230.      /*** Second parameter, depends on which token we're using.. ***/
  231.      i=0;
  232.      while (!isspace(*inputline) && (*inputline != '\0'))
  233.       secondparm[i++] = *inputline++;
  234.  
  235.      secondparm[i] = '\0';
  236.      
  237.      if (exttype == EXT_BLOCK || exttype == EXT_BLOCKREF) {
  238.       EXsetBlockname(temp, secondparm);
  239.       EXAadd(extarr, temp);
  240.       EXdestroy(temp);
  241.       return(TRUE);
  242.      }
  243.      else if (exttype == EXT_VIEW)
  244.       EXsetObjtype(temp, *secondparm);
  245.      
  246.      if (*inputline == '\0') return(FALSE);
  247.  
  248.      inputline = skip_whitespace(inputline);
  249.      if (*inputline == '\0') return(FALSE);
  250.  
  251.      /*** Prefix ***/
  252.      i=0;
  253.      while (!isspace(*inputline) && (*inputline != '\0'))
  254.       prefix[i++] = *inputline++;
  255.      if (*inputline == '\0') return(FALSE);
  256.      prefix[i]='\0';
  257.      EXsetPrefix(temp, prefix);
  258.  
  259.      inputline = skip_whitespace(inputline);
  260.      if (*inputline == '\0') return(FALSE);
  261.  
  262.      /*** Gopher + view type ***/
  263.      i=0;
  264.      while (!isspace(*inputline) && (*inputline != '\0'))
  265.       Gplustype[i++]= *inputline++;
  266.  
  267.      Gplustype[i] = '\0';
  268.      EXsetView(temp, Gplustype);
  269.  
  270.      inputline = skip_whitespace(inputline);
  271.  
  272.      /** Gopher+ view language **/
  273.      i=0;
  274.      while (!isspace(*inputline) && (*inputline != '\0'))
  275.       Gpluslang[i++]= *inputline++;
  276.  
  277.      Gpluslang[i] = '\0';
  278.      if (strlen(Gpluslang) > 0)
  279.       EXsetVLang(temp, Gpluslang);
  280.  
  281.      EXsetExttype(temp, EXT_VIEW);
  282.  
  283.      EXAadd(extarr, temp);
  284.      EXdestroy(temp);
  285.      return(TRUE);
  286. }
  287.  
  288.